package com.lzx.iteam;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.lzx.iteam.base.FindViewById;
import com.lzx.iteam.base.MyBaseActivity;
import com.lzx.iteam.util.StringUtil;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 08月 03日
 * Time: 下午5:14
 *
 * @QQ : 1234567890
 * **********************************
 */
public class CRMRemarkActivity extends MyBaseActivity implements View.OnClickListener{

    @FindViewById(id = R.id.title_ll_back)
    private LinearLayout mLayoutBack;
    @FindViewById(id = R.id.title_tv_right)
    private TextView mTvRight;
    @FindViewById(id = R.id.title_tv_center)
    private TextView mTvTitle;
    @FindViewById(id = R.id.crm_remark_edit)
    private EditText mEdit;

    private int mFlag;
    private String mRemark;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, R.layout.crm_remark_layout);
    }

    @Override
    public void initListener() {
        mTvRight.setOnClickListener(this);
        mLayoutBack.setOnClickListener(this);
    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        mFlag = intent.getIntExtra("action_type",0);
        mRemark = intent.getStringExtra("crm_remark");
        mTvTitle.setText("备注");
        mTvRight.setText("完成");
        if (!StringUtil.isEmpty(mRemark)){
            mEdit.setText(mRemark);
            mEdit.setSelection(mRemark.length());
        }else{
            mEdit.setHint("暂无备注");
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_ll_back:
                finish();
                break;
            case R.id.title_tv_right:
                mRemark = mEdit.getText().toString().trim();
                if (mRemark.length() > 200){
                    Toast.makeText(CRMRemarkActivity.this, "备注信息200字符以内", Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent remark = new Intent();
                remark.putExtra("crm_remark",mRemark);
                setResult(RESULT_OK,remark);
                finish();
                break;

        }
    }
}
